package io.renren.modules.area_region.entity;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationTargetException;

import org.apache.commons.lang.StringUtils;
import org.phprpc.util.PHPSerializer;

import io.renren.common.utils.CommonUtils;

public class Trans {

	private String start_weight; //最小重量 g
	private String top_weight;   //最大重量 g
	private String base_weight;  //首重重量 g
	private String step_weight;  //续重重量 g 
	private String base_fee;     //首重费用 元
	private String step_fee;     //续重费用 元
	private String discount;     //折扣
	private String time;         //时间 
	private String declaration;  //报关费用
	private String volueme;      //体积重

	public String getStart_weight() {
		return start_weight;
	}

	public void setStart_weight(String start_weight) {
		this.start_weight = start_weight;
	}

	public String getTop_weight() {
		return top_weight;
	}

	public void setTop_weight(String top_weight) {
		this.top_weight = top_weight;
	}

	public String getBase_weight() {
		return base_weight;
	}

	public void setBase_weight(String base_weight) {
		this.base_weight = base_weight;
	}

	public String getBase_fee() {
		return base_fee;
	}

	public void setBase_fee(String base_fee) {
		this.base_fee = base_fee;
	}

	public String getStep_weight() {
		return step_weight;
	}

	public void setStep_weight(String step_weight) {
		this.step_weight = step_weight;
	}

	public String getStep_fee() {
		return step_fee;
	}

	public void setStep_fee(String step_fee) {
		this.step_fee = step_fee;
	}

	public String getDiscount() {
		return discount;
	}

	public void setDiscount(String discount) {
		this.discount = discount;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getDeclaration() {
		return declaration;
	}

	public void setDeclaration(String declaration) {
		this.declaration = declaration;
	}

	public String getVolueme() {
		return volueme;
	}

	public void setVolueme(String volueme) {
		this.volueme = volueme;
	}

	@Override
	public String toString() {
		return "Trans [start_weight=" + start_weight + ", top_weight=" + top_weight + ", base_weight=" + base_weight
				+ ", base_fee=" + base_fee + ", step_weight=" + step_weight + ", step_fee=" + step_fee + ", discount="
				+ discount + ", time=" + time + ", declaration=" + declaration + ", volueme=" + volueme + "]";
	}

	//反序列化
	public static Trans getUnserialize(String content) {
		PHPSerializer p = new PHPSerializer();
		if (StringUtils.isEmpty(content))
			return null;
		Trans t = null;
		try {
			t = (Trans) p.unserialize(content.getBytes(), Trans.class);
		} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			e.printStackTrace();
		}
		return t;
	}
	//序列化
	public static String serializeToString(Object obj)  {
		ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
		ObjectOutputStream objOut;
		String str = null;
		try {
			objOut = new ObjectOutputStream(byteOut);
			objOut.writeObject(obj);
			str = byteOut.toString("ISO-8859-1");// 此处只能是ISO-8859-1,但是不会影响中文使用
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}
	

	public static void main(String[] args) {
		String content="a:10:{s:12:\"start_weight\";s:1:\"1\";s:10:\"top_weight\";s:4:\"2000\";s:11:\"base_weight\";s:3:\"500\";s:8:\"base_fee\";s:3:\"124\";s:11:\"step_weight\";s:3:\"500\";s:8:\"step_fee\";s:2:\"33\";s:4:\"time\";s:15:\"3-5个工作日\";s:11:\"declaration\";s:2:\"20\";s:7:\"volueme\";s:1:\"1\";s:8:\"discount\";s:0:\"\";}";
		Trans trans = Trans.getUnserialize(content);
		System.out.println(trans);
		content="a:10:{s:12:\"start_weight\";s:4:\"2001\";s:10:\"top_weight\";s:5:\"20000\";s:11:\"base_weight\";s:3:\"500\";s:8:\"base_fee\";s:3:\"124\";s:11:\"step_weight\";s:3:\"500\";s:8:\"step_fee\";s:2:\"33\";s:4:\"time\";s:15:\"3-5个工作日\";s:11:\"declaration\";s:0:\"\";s:7:\"volueme\";s:1:\"1\";s:8:\"discount\";s:0:\"\";}";
		trans = Trans.getUnserialize(content);
		System.out.println(trans);
		String xString="{\"name\": \"BeJson\", \"url\": \"http://www.bejson.com\", \"page\": 88, \"isNonProfit\": true }";
		String serializeToString = Trans.serializeToString(xString);
		System.out.println(content);
		System.out.println(serializeToString);
	}
	

}
